package ink.lovejinhu.leetcode;

/**
 * @author jinhu
 * created 2021-07-13 10:45
 */
public class Solution_0338 {
    /**
     * @param n
     * @return
     */
    public int[] countBits(int n) {
        int[] res = new int[n + 1];
        int count = 0;
        for (int i = 0; i <= n; i++) {
            res[i] = getBit(i);
        }
        return res;
    }

    public int getBit(int n) {
        int count = 0;
        int temp = 0;
        while (n > 0) {
            temp = n % 2;
            if (temp == 1) {
                count++;
            }
            n /= 2;
        }
        return count;
    }
}
